package com.ww.sound_emission.controller;

import com.ww.sound_emission.domain.Works;
import com.ww.sound_emission.service.WorksService;
import com.ww.sound_emission.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/works")
public class WorkController {

    @Autowired
    private WorksService workService;

    // 获取所有作品
    @GetMapping
    public Result<List<Works>> getAllWorks() {
        List<Works> works = workService.list();
        return Result.success(works);
    }

    // 添加作品
    @PostMapping
    public Result<String> addWork(@RequestBody Works work) {
        workService.save(work);
        return Result.success("作品添加成功");
    }

    // 删除作品
    @DeleteMapping("/{id}")
    public Result<String> deleteWork(@PathVariable Long id) {
        workService.removeById(id);
        return Result.success("作品删除成功");
    }
}